<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>Spring-day01 | 阿毛的博客</title><meta name="keywords" content="spring"><meta name="author" content="myl"><meta name="copyright" content="myl"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Spring-day01   IoC1)Spring简介1.1)什么是框架 源自于建筑学，隶属土木工程，后发展到软件工程领域  软件工程框架：经过验证的，具有一定功能的，半成品软件  经过验证  具有一定功能  半成品      1.2)框架的作用 1.3)Spring是什么Spring是分层的JavaSE&#x2F;EE应用full-stack轻量级开源框架  1.4)Spring的体系结构 1">
<meta property="og:type" content="article">
<meta property="og:title" content="Spring-day01">
<meta property="og:url" content="https://gitee.com/tgreen/myl-mm.git/2022/05/09/Spring-day01/index.html">
<meta property="og:site_name" content="阿毛的博客">
<meta property="og:description" content="Spring-day01   IoC1)Spring简介1.1)什么是框架 源自于建筑学，隶属土木工程，后发展到软件工程领域  软件工程框架：经过验证的，具有一定功能的，半成品软件  经过验证  具有一定功能  半成品      1.2)框架的作用 1.3)Spring是什么Spring是分层的JavaSE&#x2F;EE应用full-stack轻量级开源框架  1.4)Spring的体系结构 1">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg">
<meta property="article:published_time" content="2022-05-09T08:57:09.786Z">
<meta property="article:modified_time" content="2022-05-09T11:34:45.212Z">
<meta property="article:author" content="myl">
<meta property="article:tag" content="spring">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg"><link rel="shortcut icon" href="/myl-mm/img/favicon.png"><link rel="canonical" href="https://gitee.com/tgreen/myl-mm.git/2022/05/09/Spring-day01/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/myl-mm/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/myl-mm/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Spring-day01',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-05-09 19:34:45'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/myl-mm/archives/"><div class="headline">文章</div><div class="length-num">22</div></a><a href="/myl-mm/tags/"><div class="headline">标签</div><div class="length-num">11</div></a><a href="/myl-mm/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myl-mm/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/myl-mm/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/myl-mm/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/long1.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/myl-mm/">阿毛的博客</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myl-mm/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/myl-mm/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/myl-mm/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Spring-day01</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-05-09T08:57:09.786Z" title="发表于 2022-05-09 16:57:09">2022-05-09</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-05-09T11:34:45.212Z" title="更新于 2022-05-09 19:34:45">2022-05-09</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/myl-mm/categories/spring/">spring</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Spring-day01"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Spring-day01-IoC"><a href="#Spring-day01-IoC" class="headerlink" title="Spring-day01   IoC"></a>Spring-day01   IoC</h1><h2 id="1-Spring简介"><a href="#1-Spring简介" class="headerlink" title="1)Spring简介"></a>1)Spring简介</h2><h3 id="1-1-什么是框架"><a href="#1-1-什么是框架" class="headerlink" title="1.1)什么是框架"></a>1.1)什么是框架</h3><ul>
<li><p>源自于建筑学，隶属土木工程，后发展到软件工程领域</p>
</li>
<li><p>软件工程框架：经过验证的，具有一定功能的，半成品软件</p>
<ul>
<li><p>经过验证</p>
</li>
<li><p>具有一定功能</p>
</li>
<li><p>半成品</p>
</li>
</ul>
</li>
</ul>
<p><img src="/myl-mm/assets%5C1590631254933.png" alt="1590631254933"></p>
<h3 id="1-2-框架的作用"><a href="#1-2-框架的作用" class="headerlink" title="1.2)框架的作用"></a>1.2)框架的作用</h3><p><img src="/myl-mm/assets%5C1590631300743.png" alt="1590631300743"></p>
<h3 id="1-3-Spring是什么"><a href="#1-3-Spring是什么" class="headerlink" title="1.3)Spring是什么"></a>1.3)Spring是什么</h3><p>Spring是分层的JavaSE&#x2F;EE应用full-stack轻量级开源框架</p>
<p><img src="/myl-mm/assets%5C1590631495077.png" alt="1590631495077"></p>
<h3 id="1-4-Spring的体系结构"><a href="#1-4-Spring的体系结构" class="headerlink" title="1.4)Spring的体系结构"></a>1.4)Spring的体系结构</h3><p><img src="/myl-mm/assets%5C1590631552693.png" alt="1590631552693"></p>
<h3 id="1-5-Spring的发展历史"><a href="#1-5-Spring的发展历史" class="headerlink" title="1.5)Spring的发展历史"></a>1.5)Spring的发展历史</h3><p><img src="/myl-mm/assets%5C1590631606747.png" alt="1590631606747"></p>
<h3 id="1-6-Spring优势"><a href="#1-6-Spring优势" class="headerlink" title="1.6)Spring优势"></a>1.6)Spring优势</h3><table>
<thead>
<tr>
<th>Spring的优势</th>
<th></th>
</tr>
</thead>
<tbody><tr>
<td>方便解耦，简化开发</td>
<td>第一天</td>
</tr>
<tr>
<td>方便集成各种优秀框架</td>
<td>第一天</td>
</tr>
<tr>
<td>方便程序的测试</td>
<td>第二天</td>
</tr>
<tr>
<td>AOP编程的支持</td>
<td>第三天</td>
</tr>
<tr>
<td>声明式事务的支持</td>
<td>第四天</td>
</tr>
<tr>
<td>降低JavaEE API的使用难度</td>
<td>第四天</td>
</tr>
<tr>
<td>Java源码是经典学习范例</td>
<td>长期学习</td>
</tr>
</tbody></table>
<h2 id="2-IoC简介"><a href="#2-IoC简介" class="headerlink" title="2)IoC简介"></a>2)IoC简介</h2><h3 id="2-1-优质程序代码的制作原则"><a href="#2-1-优质程序代码的制作原则" class="headerlink" title="2.1)优质程序代码的制作原则"></a>2.1)优质程序代码的制作原则</h3><p><img src="/myl-mm/assets%5C1590636507198.png" alt="1590636507198"></p>
<h3 id="2-2-耦合与内聚"><a href="#2-2-耦合与内聚" class="headerlink" title="2.2)耦合与内聚"></a>2.2)耦合与内聚</h3><ul>
<li><p>耦合（Coupling）：代码书写过程中所使用技术的结合紧密度，用于衡量软件中各个模块之间的互联程度</p>
</li>
<li><p>内聚（Cohesion）：代码书写过程中单个模块内部各组成部分间的联系，用于衡量软件中各个功能模块内部的功能联系</p>
</li>
</ul>
<p><img src="/myl-mm/assets%5C1590636557953.png" alt="1590636557953"></p>
<ul>
<li>程序书写的目标：高内聚，低耦合<ul>
<li>就是同一个模块内的各个元素之间要高度紧密，但是各个模块之间的相互依存度却不要那么紧密</li>
</ul>
</li>
</ul>
<h3 id="2-3-工厂模式发展史"><a href="#2-3-工厂模式发展史" class="headerlink" title="2.3)工厂模式发展史"></a>2.3)工厂模式发展史</h3><p><img src="/myl-mm/assets%5C1590636616069.png" alt="1590636616069"></p>
<p><img src="/myl-mm/assets%5C1590636644096.png" alt="1590636644096"></p>
<p><img src="/myl-mm/assets%5C1590636661026.png" alt="1590636661026"></p>
<h3 id="2-4-Spring发展历程"><a href="#2-4-Spring发展历程" class="headerlink" title="2.4)Spring发展历程"></a>2.4)Spring发展历程</h3><p><img src="/myl-mm/assets%5C1590636704098.png" alt="1590636704098"></p>
<h3 id="2-5-IoC"><a href="#2-5-IoC" class="headerlink" title="2.5)IoC"></a>2.5)IoC</h3><ul>
<li><p>IoC（Inversion Of Control）控制反转，Spring反向控制应用程序所需要使用的外部资源</p>
</li>
<li><p>Spring控制的资源全部放置在Spring容器中，该容器称为IoC容器</p>
<p><img src="/myl-mm/assets%5C1590636750876.png" alt="1590636750876"></p>
</li>
</ul>
<h2 id="3-入门案例"><a href="#3-入门案例" class="headerlink" title="3)入门案例"></a>3)入门案例</h2><h3 id="3-1-案例环境说明"><a href="#3-1-案例环境说明" class="headerlink" title="3.1)案例环境说明"></a>3.1)案例环境说明</h3><ul>
<li><p>模拟三层架构中表现层调用业务层功能</p>
<ul>
<li><p>表现层：UserApp模拟UserServlet（使用main方法模拟）</p>
</li>
<li><p>业务层：UserService</p>
</li>
</ul>
</li>
</ul>
<h3 id="3-2-IoC入门案例制作步骤"><a href="#3-2-IoC入门案例制作步骤" class="headerlink" title="3.2)IoC入门案例制作步骤"></a>3.2)IoC入门案例制作步骤</h3><p>1.导入spring坐标（5.1.9.release）</p>
<p>2.编写业务层与表现层（模拟）接口与实现类</p>
<p>3.建立spring配置文件</p>
<p>4.配置所需资源（Service）为spring控制的资源</p>
<p>5.表现层（App）通过spring获取资源（Service实例）</p>
<p><img src="/myl-mm/assets%5C1590637353510.png" alt="1590637353510"></p>
<h4 id="3-2-1-IoC入门案例制作步骤-1"><a href="#3-2-1-IoC入门案例制作步骤-1" class="headerlink" title="3.2.1)IoC入门案例制作步骤-1"></a>3.2.1)IoC入门案例制作步骤-1</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-context<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>5.1.9.RELEASE<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="3-2-2-IoC入门案例制作步骤-2"><a href="#3-2-2-IoC入门案例制作步骤-2" class="headerlink" title="3.2.2)IoC入门案例制作步骤-2"></a>3.2.2)IoC入门案例制作步骤-2</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">UserService</span> &#123;</span><br><span class="line">	<span class="comment">//业务方法  </span></span><br><span class="line">	<span class="keyword">void</span> <span class="title function_">save</span><span class="params">()</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="3-2-3-IoC入门案例制作步骤-3"><a href="#3-2-3-IoC入门案例制作步骤-3" class="headerlink" title="3.2.3)IoC入门案例制作步骤-3"></a>3.2.3)IoC入门案例制作步骤-3</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">UserServiceImpl</span> <span class="keyword">implements</span> <span class="title class_">UserService</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">save</span><span class="params">()</span> &#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;user service running...&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="3-2-4-IoC入门案例制作步骤-4"><a href="#3-2-4-IoC入门案例制作步骤-4" class="headerlink" title="3.2.4)IoC入门案例制作步骤-4"></a>3.2.4)IoC入门案例制作步骤-4</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">beans</span> <span class="attr">xmlns</span>=<span class="string">&quot;http://www.springframework.org/schema/beans&quot;</span></span></span><br><span class="line"><span class="tag">       <span class="attr">xmlns:xsi</span>=<span class="string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span></span><br><span class="line"><span class="tag">       <span class="attr">xsi:schemaLocation</span>=<span class="string">&quot;http://www.springframework.org/schema/beans</span></span></span><br><span class="line"><span class="string"><span class="tag">        https://www.springframework.org/schema/beans/spring-beans.xsd&quot;</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 1.创建spring控制的资源--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;userService&quot;</span> <span class="attr">class</span>=<span class="string">&quot;com.itheima.service.impl.UserServiceImpl&quot;</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">beans</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="3-2-5-IoC入门案例制作步骤-5"><a href="#3-2-5-IoC入门案例制作步骤-5" class="headerlink" title="3.2.5)IoC入门案例制作步骤-5"></a>3.2.5)IoC入门案例制作步骤-5</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">UserApp</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="comment">//2.加载配置文件</span></span><br><span class="line">        <span class="type">ApplicationContext</span> <span class="variable">ctx</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ClassPathXmlApplicationContext</span>(<span class="string">&quot;applicationContext.xml&quot;</span>);</span><br><span class="line">        <span class="comment">//3.获取资源</span></span><br><span class="line">        <span class="type">UserService</span> <span class="variable">userService</span> <span class="operator">=</span> (UserService) ctx.getBean(<span class="string">&quot;userService&quot;</span>);</span><br><span class="line">        userService.save();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="4-IoC配置（XML格式）"><a href="#4-IoC配置（XML格式）" class="headerlink" title="4)IoC配置（XML格式）"></a>4)IoC配置（XML格式）</h2><h3 id="4-1-bean"><a href="#4-1-bean" class="headerlink" title="4.1)bean"></a>4.1)bean</h3><ul>
<li><p>名称：bean</p>
</li>
<li><p>类型：<strong>标签</strong></p>
</li>
<li><p>归属：beans标签</p>
</li>
<li><p>作用：定义spring中的资源，受此标签定义的资源将受到spring控制</p>
</li>
<li><p>格式：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">beans</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">beans</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>基本属性：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;beanId&quot;</span> <span class="attr">name</span>=<span class="string">&quot;beanName1,beanName2&quot;</span> <span class="attr">class</span>=<span class="string">&quot;ClassName&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>​	id：bean的名称，通过id值获取bean</p>
<p>​	class：bean的类型</p>
<p>​	name：bean的名称，可以通过name值获取bean，用于多人配合时给bean起别名</p>
</li>
</ul>
<h3 id="4-2-bean属性scope"><a href="#4-2-bean属性scope" class="headerlink" title="4.2)bean属性scope"></a>4.2)bean属性scope</h3><ul>
<li><p>名称：scope</p>
</li>
<li><p>类型：<strong>属性</strong></p>
</li>
<li><p>归属：bean标签</p>
</li>
<li><p>作用：定义bean的作用范围</p>
</li>
<li><p>格式：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">scope</span>=<span class="string">&quot;singleton&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>取值：</p>
<ul>
<li>singleton：设定创建出的对象保存在spring容器中，是一个单例的对象</li>
<li>prototype：设定创建出的对象保存在spring容器中，是一个非单例的对象</li>
<li>request、session、application、 websocket ：设定创建出的对象放置在web容器对应的位置</li>
</ul>
</li>
</ul>
<h3 id="4-3-bean生命周期"><a href="#4-3-bean生命周期" class="headerlink" title="4.3)bean生命周期"></a>4.3)bean生命周期</h3><ul>
<li><p>名称：init-method，destroy-method</p>
</li>
<li><p>类型：<strong>属性</strong></p>
</li>
<li><p>归属：bean标签</p>
</li>
<li><p>作用：定义bean对象在初始化或销毁时完成的工作</p>
</li>
<li><p>格式：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">init-method</span>=<span class="string">&quot;init&quot;</span> <span class="attr">destroy-method</span>=<span class="string">&quot;destroy&gt;&lt;/bean&gt;</span></span></span><br></pre></td></tr></table></figure>
</li>
<li><p>取值：bean对应的类中对应的具体方法名</p>
</li>
<li><p>注意事项：</p>
<ul>
<li><p>当scope&#x3D;“singleton”时，spring容器中有且仅有一个对象，init方法在创建容器时仅执行一次</p>
</li>
<li><p>当scope&#x3D;“prototype”时，spring容器要创建同一类型的多个对象，init方法在每个对象创建时均执行一次</p>
</li>
<li><p>当scope&#x3D;“singleton”时，关闭容器会导致bean实例的销毁，调用destroy方法一次</p>
</li>
<li><p>当scope&#x3D;“prototype”时，对象的销毁由垃圾回收机制gc()控制，destroy方法将不会被执行</p>
</li>
</ul>
</li>
</ul>
<h3 id="4-4-bean对象创建方式（了解）"><a href="#4-4-bean对象创建方式（了解）" class="headerlink" title="4.4)bean对象创建方式（了解）"></a>4.4)bean对象创建方式（了解）</h3><p>(1)factory-bean</p>
<ul>
<li><p>名称：factory-bean</p>
</li>
<li><p>类型：<strong>属性</strong></p>
</li>
<li><p>归属：bean标签</p>
</li>
<li><p>作用：定义bean对象创建方式，使用静态工厂的形式创建bean，兼容早期遗留系统的升级工作</p>
</li>
<li><p>格式：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">class</span>=<span class="string">&quot;FactoryClassName&quot;</span> <span class="attr">factory-method</span>=<span class="string">&quot;factoryMethodName&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>取值：工厂bean中用于获取对象的静态方法名</p>
</li>
<li><p>注意事项：</p>
<ul>
<li>class属性必须配置成静态工厂的类名</li>
</ul>
</li>
</ul>
<p>(2)factory-bean，factory-method</p>
<ul>
<li><p>名称：factory-bean，factory-method</p>
</li>
<li><p>类型：<strong>属性</strong></p>
</li>
<li><p>归属：bean标签</p>
</li>
<li><p>作用：定义bean对象创建方式，使用实例工厂的形式创建bean，兼容早期遗留系统的升级工作</p>
</li>
<li><p>格式：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">factory-bean</span>=<span class="string">&quot;factoryBeanId&quot;</span> <span class="attr">factory-method</span>=<span class="string">&quot;factoryMethodName&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>取值：工厂bean中用于获取对象的实例方法名</p>
</li>
<li><p>注意事项：</p>
<ul>
<li><p>使用实例工厂创建bean首先需要将实例工厂配置bean，交由spring进行管理</p>
</li>
<li><p>factory-bean是实例工厂的beanId</p>
</li>
</ul>
</li>
</ul>
<h3 id="4-5-DI"><a href="#4-5-DI" class="headerlink" title="4.5)DI"></a>4.5)DI</h3><ul>
<li><p>IoC（Inversion Of Control）控制翻转，Spring反向控制应用程序所需要使用的外部资源</p>
</li>
<li><p>DI（Dependency Injection）依赖注入，应用程序运行依赖的资源由Spring为其提供，资源进入应用程序的方式称为注入</p>
</li>
</ul>
<p><img src="/myl-mm/assets%5C1590659778689.png" alt="1590659778689"></p>
<p>IoC与DI的关系</p>
<ul>
<li><p>IoC与DI是同一件事站在不同角度看待问题</p>
</li>
<li><p>半杯水</p>
</li>
<li></li>
<li><p><img src="/myl-mm/assets%5C1590659854696.png" alt="1590659854696">set注入（主流）</p>
</li>
</ul>
<h3 id="4-6-set注入（主流）"><a href="#4-6-set注入（主流）" class="headerlink" title="4.6)set注入（主流）"></a>4.6)set注入（主流）</h3><ul>
<li><p>名称：property</p>
</li>
<li><p>类型：<strong>标签</strong></p>
</li>
<li><p>归属：bean标签</p>
</li>
<li><p>作用：使用set方法的形式为bean提供资源</p>
</li>
<li><p>格式：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;bean&gt;</span><br><span class="line">	&lt;property /&gt;</span><br><span class="line">&lt;/bean&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>基本属性：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;propertyName&quot;</span> <span class="attr">value</span>=<span class="string">&quot;propertyValue&quot;</span> <span class="attr">ref</span>=<span class="string">&quot;beanId&quot;</span>/&gt;</span></span><br></pre></td></tr></table></figure></li>
</ul>
<p>​	name：对应bean中的属性名，要求该属性必须提供可访问的set方法（严格规范为此名称是set方法对应名称）</p>
<p>​	value：设定非引用类型属性对应的值，不能与ref同时使用</p>
<p>​	ref：设定引用类型属性对应bean的id ，不能与value同时使用</p>
<ul>
<li>注意：一个bean可以有多个property标签</li>
</ul>
<h3 id="4-7-构造器注入（了解）"><a href="#4-7-构造器注入（了解）" class="headerlink" title="4.7)构造器注入（了解）"></a>4.7)构造器注入（了解）</h3><ul>
<li><p>名称：constructor-arg</p>
</li>
<li><p>类型：<strong>标签</strong></p>
</li>
<li><p>归属：bean标签</p>
</li>
<li><p>作用：使用构造方法的形式为bean提供资源，兼容早期遗留系统的升级工作</p>
</li>
<li><p>格式：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">bean</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">constructor-arg</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>基本属性：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;argsName&quot;</span> <span class="attr">value</span>=<span class="string">&quot;argsValue /&gt;</span></span></span><br></pre></td></tr></table></figure></li>
</ul>
<p>​	name：对应bean中的构造方法所携带的参数名</p>
<p>​	value：设定非引用类型构造方法参数对应的值，不能与ref同时使用</p>
<p>其他属性：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">index</span>=<span class="string">&quot;arg-index&quot;</span> <span class="attr">type</span>=<span class="string">&quot;arg-type&quot;</span> <span class="attr">ref</span>=<span class="string">&quot;beanId&quot;</span>/&gt;</span></span><br></pre></td></tr></table></figure>

<p>​	ref：设定引用类型构造方法参数对应bean的id ，不能与value同时使用</p>
<p>​	type ：设定构造方法参数的类型，用于按类型匹配参数或进行类型校验</p>
<p>​	index ：设定构造方法参数的位置，用于按位置匹配参数，参数index值从0开始计数</p>
<ul>
<li>注意：一个bean可以有多个constructor-arg标签</li>
</ul>
<h3 id="4-8-集合类型数据注入"><a href="#4-8-集合类型数据注入" class="headerlink" title="4.8)集合类型数据注入"></a>4.8)集合类型数据注入</h3><ul>
<li><p>名称：array，list，set，map，props</p>
</li>
<li><p>类型：<strong>标签</strong></p>
</li>
<li><p>归属：property标签 或 constructor-arg标签</p>
</li>
<li><p>作用：注入集合数据类型属性</p>
</li>
<li><p>格式：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">property</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">list</span>&gt;</span><span class="tag">&lt;/<span class="name">list</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br></pre></td></tr></table></figure></li>
</ul>
<p>(1)集合类型数据注入——list</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;al&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">list</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">value</span>&gt;</span>itheima<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">value</span>&gt;</span>66666<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">list</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>(2)集合类型数据注入——props</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;properties&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">props</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">prop</span> <span class="attr">key</span>=<span class="string">&quot;name&quot;</span>&gt;</span>itheima666<span class="tag">&lt;/<span class="name">prop</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">prop</span> <span class="attr">key</span>=<span class="string">&quot;value&quot;</span>&gt;</span>666666<span class="tag">&lt;/<span class="name">prop</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">props</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>(3)集合类型数据注入——array （了解）</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;arr&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">array</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">value</span>&gt;</span>123456<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">value</span>&gt;</span>66666<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">array</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>(4)集合类型数据注入——set（了解）</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"> <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;hs&quot;</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">set</span>&gt;</span></span><br><span class="line">         <span class="tag">&lt;<span class="name">value</span>&gt;</span>itheima<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">         <span class="tag">&lt;<span class="name">value</span>&gt;</span>66666<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;/<span class="name">set</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>(5)集合类型数据注入——map（了解）</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;hm&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">map</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">entry</span> <span class="attr">key</span>=<span class="string">&quot;name&quot;</span> <span class="attr">value</span>=<span class="string">&quot;itheima66666&quot;</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">entry</span> <span class="attr">key</span>=<span class="string">&quot;value&quot;</span> <span class="attr">value</span>=<span class="string">&quot;6666666666&quot;</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">map</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="4-9-使用p命名空间简化配置（了解）"><a href="#4-9-使用p命名空间简化配置（了解）" class="headerlink" title="4.9)使用p命名空间简化配置（了解）"></a>4.9)使用p命名空间简化配置（了解）</h3><ul>
<li><p>名称：p:propertyName，p:propertyName-ref</p>
</li>
<li><p>类型：<strong>属性</strong></p>
</li>
<li><p>归属：bean标签</p>
</li>
<li><p>作用：为bean注入属性值</p>
</li>
<li><p>格式：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">p:propertyName</span>=<span class="string">&quot;propertyValue&quot;</span> <span class="attr">p:propertyName-ref</span>=<span class="string">&quot;beanId&quot;</span>/&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>注意：使用p命令空间需要先开启spring对p命令空间的的支持，在beans标签中添加对应空间支持</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">beans</span> <span class="attr">xmlns</span>=<span class="string">&quot;http://www.springframework.org/schema/beans&quot;</span>    <span class="attr">xmlns:xsi</span>=<span class="string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>    <span class="attr">xmlns:p</span>=<span class="string">&quot;http://www.springframework.org/schema/p&quot;</span>       <span class="attr">xsi:schemaLocation</span>=<span class="string">&quot;http://www.springframework.org/schema/beans     https://www.springframework.org/schema/beans/spring-beans.xsd&quot;</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>后续课程中还将开启其他的命名空间，方式同上</p>
</li>
<li><p>案例：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">bean</span></span></span><br><span class="line"><span class="tag">      <span class="attr">id</span>=<span class="string">&quot;userService&quot;</span></span></span><br><span class="line"><span class="tag">      <span class="attr">class</span>=<span class="string">&quot;com.itheima.service.impl.UserServiceImpl&quot;</span></span></span><br><span class="line"><span class="tag">      <span class="attr">p:userDao-ref</span>=<span class="string">&quot;userDao&quot;</span></span></span><br><span class="line"><span class="tag">      <span class="attr">p:bookDao-ref</span>=<span class="string">&quot;bookDao&quot;</span></span></span><br><span class="line"><span class="tag">      /&gt;</span></span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="4-10-SpEL-（了解）"><a href="#4-10-SpEL-（了解）" class="headerlink" title="4.10)SpEL （了解）"></a>4.10)SpEL （了解）</h3><ul>
<li><p>Spring提供了对EL表达式的支持，统一属性注入格式</p>
</li>
<li><p>类型：<strong>属性值</strong></p>
</li>
<li><p>归属：value属性值</p>
</li>
<li><p>作用：为bean注入属性值</p>
</li>
<li><p>格式：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">property</span> <span class="attr">value</span>=<span class="string">&quot;EL&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>注意：所有属性值不区分是否引用类型，统一使用value赋值</p>
</li>
<li><p>所有格式统一使用  value&#x3D;“********”</p>
<ul>
<li><p>常量  #{10}  #{3.14}  #{2e5}  #{‘itcast’}</p>
</li>
<li><p>引用bean  #{beanId}    </p>
</li>
<li><p>引用bean属性  #{beanId.propertyName}</p>
</li>
<li><p>引用bean方法  beanId.methodName().method2()</p>
</li>
<li><p>引用静态方法  T(java.lang.Math).PI</p>
</li>
<li><p>运算符支持  #{3 lt 4 &#x3D;&#x3D; 4 ge 3}</p>
</li>
<li><p>正则表达式支持  #{user.name matches‘[a-z]{6,}’}</p>
</li>
<li><p>集合支持  #{likes[3]}</p>
</li>
</ul>
</li>
<li><p>案例：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"> <span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;userService&quot;</span> <span class="attr">class</span>=<span class="string">&quot;com.itheima.service.impl.UserServiceImpl&quot;</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;userDao&quot;</span> <span class="attr">value</span>=<span class="string">&quot;#&#123;userDao&#125;&quot;</span>/&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;bookDao&quot;</span> <span class="attr">value</span>=<span class="string">&quot;#&#123;bookDao&#125;&quot;</span>/&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;num&quot;</span> <span class="attr">value</span>=<span class="string">&quot;#&#123;666666666&#125;&quot;</span>/&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;version&quot;</span> <span class="attr">value</span>=<span class="string">&quot;#&#123;&#x27;itcast&#x27;&#125;&quot;</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="4-11-properties文件"><a href="#4-11-properties文件" class="headerlink" title="4.11)properties文件"></a>4.11)properties文件</h3><ul>
<li><p>Spring提供了读取外部properties文件的机制，使用读取到的数据为bean的属性赋值</p>
</li>
<li><p>操作步骤</p>
<p>1.准备外部properties文件</p>
<p>2.开启context命名空间支持</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">xmlns:context=&quot;http://www.springframework.org/schema/context&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
<p>​		3.加载指定的properties文件</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">context:property-placeholder</span> <span class="attr">location</span>=<span class="string">&quot;classpath:filename.properties&quot;</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>​		4.使用加载的数据</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;propertyName&quot;</span> <span class="attr">value</span>=<span class="string">&quot;$&#123;propertiesName&#125;&quot;</span>/&gt;</span></span><br></pre></td></tr></table></figure>

<ul>
<li><p>注意：如果需要加载所有的properties文件，可以使用<code>*.properties</code>表示加载所有的properties文件</p>
</li>
<li><p>注意：读取数据使用**${propertiesName}<strong>格式进行，其中</strong>propertiesName**指properties文件中的属性名</p>
</li>
</ul>
<h3 id="4-12-团队开发"><a href="#4-12-团队开发" class="headerlink" title="4.12)团队开发"></a>4.12)团队开发</h3><ul>
<li><p>名称：import</p>
</li>
<li><p>类型：<strong>标签</strong></p>
</li>
<li><p>归属：beans标签</p>
</li>
<li><p>作用：在当前配置文件中导入其他配置文件中的项</p>
</li>
<li><p>格式：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">beans</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">import</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">beans</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>基本属性：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">import</span> <span class="attr">resource</span>=<span class="string">“config.xml</span>&quot;/&gt;</span></span><br></pre></td></tr></table></figure></li>
</ul>
<p>​	resource：加载的配置文件名</p>
<ul>
<li><p>Spring容器加载多个配置文件</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">new</span> <span class="title class_">ClassPathXmlApplicationContext</span>(<span class="string">&quot;config1.xml&quot;</span>,<span class="string">&quot;config2.xml&quot;</span>);</span><br></pre></td></tr></table></figure>
</li>
<li><p>Spring容器中的bean定义冲突问题</p>
<ul>
<li><p>同id的bean，后定义的覆盖先定义的</p>
</li>
<li><p>导入配置文件可以理解为将导入的配置文件复制粘贴到对应位置</p>
</li>
<li><p>导入配置文件的顺序与位置不同可能会导致最终程序运行结果不同</p>
</li>
</ul>
</li>
</ul>
<h3 id="4-13-ApplicationContext"><a href="#4-13-ApplicationContext" class="headerlink" title="4.13)ApplicationContext"></a>4.13)ApplicationContext</h3><p>1.ApplicationContext是一个接口，提供了访问spring容器的API</p>
<p>2.ClassPathXmlApplicationContext是一个类，实现了上述功能</p>
<p>3.ApplicationContext的顶层接口是BeanFactory</p>
<p>4.BeanFactory定义了bean相关的最基本操作</p>
<p>5.ApplicationContext在BeanFactory基础上追加了若干新功能</p>
<p><strong>对比BeanFactory</strong></p>
<p>1.BeanFactory创建的bean采用延迟加载形式，使用才创建</p>
<p>2.ApplicationContext创建的bean默认采用立即加载形式</p>
<p><strong>FileSystemXmlApplicationContext</strong></p>
<p>可以加载文件系统中任意位置的配置文件，而ClassPathXmlApplicationContext只能加载类路径下的配置文件</p>
<p><img src="/myl-mm/assets%5C1591021082290.png" alt="1591021082290"></p>
<p><strong>BeanFactory</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">Resource</span> <span class="variable">res</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ClassPathResource</span>(<span class="string">&quot;applicationContext.xml&quot;</span>);</span><br><span class="line"><span class="type">BeanFactory</span> <span class="variable">bf</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">XmlBeanFactory</span>(res);</span><br><span class="line"><span class="type">UserService</span> <span class="variable">userService</span> <span class="operator">=</span> (UserService)bf.getBean(<span class="string">&quot;userService&quot;</span>);</span><br></pre></td></tr></table></figure>

<h3 id="4-14-第三方资源配置"><a href="#4-14-第三方资源配置" class="headerlink" title="4.14)第三方资源配置"></a>4.14)第三方资源配置</h3><ul>
<li><p>阿里数据源方案Druid</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;dataSource&quot;</span> <span class="attr">class</span>=<span class="string">&quot;com.alibaba.druid.pool.DruidDataSource&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;driverClassName&quot;</span> <span class="attr">value</span>=<span class="string">&quot;com.mysql.jdbc.Driver&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;url&quot;</span> <span class="attr">value</span>=<span class="string">&quot;jdbc:mysql://localhost:3306/spring_ioc&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;username&quot;</span> <span class="attr">value</span>=<span class="string">&quot;root&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;password&quot;</span> <span class="attr">value</span>=<span class="string">&quot;root&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="5-综合案例"><a href="#5-综合案例" class="headerlink" title="5)综合案例"></a>5)综合案例</h2><h3 id="5-1-案例介绍"><a href="#5-1-案例介绍" class="headerlink" title="5.1)案例介绍"></a><strong>5.1)案例介绍</strong></h3><ul>
<li><p>使用spring整合mybatis技术，完成账户模块（Account）的基础增删改查功能</p>
</li>
<li><p>账户模块对应字段</p>
<ul>
<li><p>编号：id</p>
</li>
<li><p>账户名：name</p>
</li>
<li><p>余额：money</p>
</li>
</ul>
</li>
</ul>
<h3 id="5-2-案例分析"><a href="#5-2-案例分析" class="headerlink" title="5.2)案例分析"></a><strong>5.2)案例分析</strong></h3><p>非spring环境</p>
<p>1.实体类与表</p>
<p>2.业务层接口与实现</p>
<p>3.数据层接口</p>
<p>4.Mybatis核心配置</p>
<p>5.Mybatis映射配置</p>
<p>6.客户端程序测试功能</p>
<p>spring环境</p>
<p>1.实体类与表</p>
<p>2.业务层接口与实现（提供数据层接口的注入操作）</p>
<p>3.数据层接口</p>
<p>4.Mybatis核心配置（交给spring控制，该文件省略）</p>
<p>5.Mybatis映射配置</p>
<p>6.客户端程序测试功能（使用spring方式获取bean）</p>
<p>7.Spring核心配置文件</p>
<p>8.Druid数据源的应用（可选）</p>
<p>9.Spring整合MyBatis</p>
<h3 id="5-3-案例制作步骤——基础准备工作"><a href="#5-3-案例制作步骤——基础准备工作" class="headerlink" title="5.3)案例制作步骤——基础准备工作"></a>5.3)案例制作步骤——基础准备工作</h3><ul>
<li>环境准备</li>
</ul>
<p>1.导入Spring坐标，MyBatis坐标，MySQL坐标，Druid坐标</p>
<ul>
<li>业务类与接口准备</li>
</ul>
<p>2.创建数据库表，并制作相应的实体类Account</p>
<p>3.定义业务层接口与数据层接口</p>
<p>4.在业务层调用数据层接口，并实现业务方法的调用</p>
<ul>
<li>基础配置文件</li>
</ul>
<p>5.jdbc.properties</p>
<p>6.MyBatis映射配置文件</p>
<h3 id="5-4-案例制作步骤——整合准备工作"><a href="#5-4-案例制作步骤——整合准备工作" class="headerlink" title="5.4)案例制作步骤——整合准备工作"></a>5.4)案例制作步骤——整合准备工作</h3><ul>
<li>整合前基础准备工作</li>
</ul>
<p>1.spring配置文件，加上context命名空间，用于加载properties文件</p>
<p>2.开启加载properties文件</p>
<p>3.配置数据源druid（备用）</p>
<p>4.定义service层bean，注入dao层bean</p>
<p>5.dao的bean无需定义，使用代理自动生成</p>
<h3 id="5-5-案例制作步骤——整合工作"><a href="#5-5-案例制作步骤——整合工作" class="headerlink" title="5.5)案例制作步骤——整合工作"></a>5.5)案例制作步骤——整合工作</h3><ul>
<li>整合工作</li>
</ul>
<p>1.导入Spring整合MyBatis坐标</p>
<p>2.将mybatis配置成spring管理的bean（SqlSessionFactoryBean）</p>
<p>​	-将原始配置文件中的所有项，转入到当前配置中</p>
<p>​	数据源转换</p>
<p>​	映射转换</p>
<p>3.通过spring加载mybatis的映射配置文件到spring环境中</p>
<p>4.设置类型别名</p>
<ul>
<li>测试结果</li>
</ul>
<p>5.使用spring环境加载业务层bean，执行操作</p>
<h3 id="小节"><a href="#小节" class="headerlink" title="小节"></a><strong>小节</strong></h3><ul>
<li><p>需要专用的spring整合mybatis的jar包</p>
</li>
<li><p>Mybatis核心配置文件消失</p>
<ul>
<li><p>环境environment转换成数据源对象</p>
</li>
<li><p>映射Mapper扫描工作交由spring处理</p>
</li>
<li><p>类型别名交由spring处理</p>
</li>
</ul>
</li>
<li><p>业务发起使用spring上下文对象获取对应的bean</p>
</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://gitee.com/tgreen/myl-mm.git">myl</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://gitee.com/tgreen/myl-mm.git/2022/05/09/Spring-day01/">https://gitee.com/tgreen/myl-mm.git/2022/05/09/Spring-day01/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://gitee.com/tgreen/myl-mm.git" target="_blank">阿毛的博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/myl-mm/tags/spring/">spring</a></div><div class="post_share"><div class="social-share" data-image="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/gh/overtrue/share.js@master/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/myl-mm/2022/05/09/Spring-day02/"><img class="prev-cover" src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="onerror=null;src='/myl-mm/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Spring-day02</div></div></a></div><div class="next-post pull-right"><a href="/myl-mm/2022/05/09/dubbo-admin%E5%AE%89%E8%A3%85/"><img class="next-cover" src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="onerror=null;src='/myl-mm/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">dubbo-admin安装</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/myl-mm/2022/05/09/Spring-day02/" title="Spring-day02"><img class="cover" src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-05-09</div><div class="title">Spring-day02</div></div></a></div><div><a href="/myl-mm/2022/05/09/spring-day04/" title="Spring-day04"><img class="cover" src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-05-09</div><div class="title">Spring-day04</div></div></a></div><div><a href="/myl-mm/2022/05/09/Spring-day03/" title="Spring-day03"><img class="cover" src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-05-09</div><div class="title">Spring-day03</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/myl-mm/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">myl</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/myl-mm/archives/"><div class="headline">文章</div><div class="length-num">22</div></a><a href="/myl-mm/tags/"><div class="headline">标签</div><div class="length-num">11</div></a><a href="/myl-mm/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div><a id="card-info-btn" href="https://gitee.com/tgreen/"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">欢迎观看，又来一个！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Spring-day01-IoC"><span class="toc-number">1.</span> <span class="toc-text">Spring-day01   IoC</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-Spring%E7%AE%80%E4%BB%8B"><span class="toc-number">1.1.</span> <span class="toc-text">1)Spring简介</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-%E4%BB%80%E4%B9%88%E6%98%AF%E6%A1%86%E6%9E%B6"><span class="toc-number">1.1.1.</span> <span class="toc-text">1.1)什么是框架</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-%E6%A1%86%E6%9E%B6%E7%9A%84%E4%BD%9C%E7%94%A8"><span class="toc-number">1.1.2.</span> <span class="toc-text">1.2)框架的作用</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-3-Spring%E6%98%AF%E4%BB%80%E4%B9%88"><span class="toc-number">1.1.3.</span> <span class="toc-text">1.3)Spring是什么</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-4-Spring%E7%9A%84%E4%BD%93%E7%B3%BB%E7%BB%93%E6%9E%84"><span class="toc-number">1.1.4.</span> <span class="toc-text">1.4)Spring的体系结构</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-5-Spring%E7%9A%84%E5%8F%91%E5%B1%95%E5%8E%86%E5%8F%B2"><span class="toc-number">1.1.5.</span> <span class="toc-text">1.5)Spring的发展历史</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-6-Spring%E4%BC%98%E5%8A%BF"><span class="toc-number">1.1.6.</span> <span class="toc-text">1.6)Spring优势</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-IoC%E7%AE%80%E4%BB%8B"><span class="toc-number">1.2.</span> <span class="toc-text">2)IoC简介</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-%E4%BC%98%E8%B4%A8%E7%A8%8B%E5%BA%8F%E4%BB%A3%E7%A0%81%E7%9A%84%E5%88%B6%E4%BD%9C%E5%8E%9F%E5%88%99"><span class="toc-number">1.2.1.</span> <span class="toc-text">2.1)优质程序代码的制作原则</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-%E8%80%A6%E5%90%88%E4%B8%8E%E5%86%85%E8%81%9A"><span class="toc-number">1.2.2.</span> <span class="toc-text">2.2)耦合与内聚</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-3-%E5%B7%A5%E5%8E%82%E6%A8%A1%E5%BC%8F%E5%8F%91%E5%B1%95%E5%8F%B2"><span class="toc-number">1.2.3.</span> <span class="toc-text">2.3)工厂模式发展史</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-4-Spring%E5%8F%91%E5%B1%95%E5%8E%86%E7%A8%8B"><span class="toc-number">1.2.4.</span> <span class="toc-text">2.4)Spring发展历程</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-IoC"><span class="toc-number">1.2.5.</span> <span class="toc-text">2.5)IoC</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E5%85%A5%E9%97%A8%E6%A1%88%E4%BE%8B"><span class="toc-number">1.3.</span> <span class="toc-text">3)入门案例</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-1-%E6%A1%88%E4%BE%8B%E7%8E%AF%E5%A2%83%E8%AF%B4%E6%98%8E"><span class="toc-number">1.3.1.</span> <span class="toc-text">3.1)案例环境说明</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-IoC%E5%85%A5%E9%97%A8%E6%A1%88%E4%BE%8B%E5%88%B6%E4%BD%9C%E6%AD%A5%E9%AA%A4"><span class="toc-number">1.3.2.</span> <span class="toc-text">3.2)IoC入门案例制作步骤</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#3-2-1-IoC%E5%85%A5%E9%97%A8%E6%A1%88%E4%BE%8B%E5%88%B6%E4%BD%9C%E6%AD%A5%E9%AA%A4-1"><span class="toc-number">1.3.2.1.</span> <span class="toc-text">3.2.1)IoC入门案例制作步骤-1</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-2-2-IoC%E5%85%A5%E9%97%A8%E6%A1%88%E4%BE%8B%E5%88%B6%E4%BD%9C%E6%AD%A5%E9%AA%A4-2"><span class="toc-number">1.3.2.2.</span> <span class="toc-text">3.2.2)IoC入门案例制作步骤-2</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-2-3-IoC%E5%85%A5%E9%97%A8%E6%A1%88%E4%BE%8B%E5%88%B6%E4%BD%9C%E6%AD%A5%E9%AA%A4-3"><span class="toc-number">1.3.2.3.</span> <span class="toc-text">3.2.3)IoC入门案例制作步骤-3</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-2-4-IoC%E5%85%A5%E9%97%A8%E6%A1%88%E4%BE%8B%E5%88%B6%E4%BD%9C%E6%AD%A5%E9%AA%A4-4"><span class="toc-number">1.3.2.4.</span> <span class="toc-text">3.2.4)IoC入门案例制作步骤-4</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-2-5-IoC%E5%85%A5%E9%97%A8%E6%A1%88%E4%BE%8B%E5%88%B6%E4%BD%9C%E6%AD%A5%E9%AA%A4-5"><span class="toc-number">1.3.2.5.</span> <span class="toc-text">3.2.5)IoC入门案例制作步骤-5</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-IoC%E9%85%8D%E7%BD%AE%EF%BC%88XML%E6%A0%BC%E5%BC%8F%EF%BC%89"><span class="toc-number">1.4.</span> <span class="toc-text">4)IoC配置（XML格式）</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#4-1-bean"><span class="toc-number">1.4.1.</span> <span class="toc-text">4.1)bean</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-2-bean%E5%B1%9E%E6%80%A7scope"><span class="toc-number">1.4.2.</span> <span class="toc-text">4.2)bean属性scope</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-3-bean%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="toc-number">1.4.3.</span> <span class="toc-text">4.3)bean生命周期</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-4-bean%E5%AF%B9%E8%B1%A1%E5%88%9B%E5%BB%BA%E6%96%B9%E5%BC%8F%EF%BC%88%E4%BA%86%E8%A7%A3%EF%BC%89"><span class="toc-number">1.4.4.</span> <span class="toc-text">4.4)bean对象创建方式（了解）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-5-DI"><span class="toc-number">1.4.5.</span> <span class="toc-text">4.5)DI</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-6-set%E6%B3%A8%E5%85%A5%EF%BC%88%E4%B8%BB%E6%B5%81%EF%BC%89"><span class="toc-number">1.4.6.</span> <span class="toc-text">4.6)set注入（主流）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-7-%E6%9E%84%E9%80%A0%E5%99%A8%E6%B3%A8%E5%85%A5%EF%BC%88%E4%BA%86%E8%A7%A3%EF%BC%89"><span class="toc-number">1.4.7.</span> <span class="toc-text">4.7)构造器注入（了解）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-8-%E9%9B%86%E5%90%88%E7%B1%BB%E5%9E%8B%E6%95%B0%E6%8D%AE%E6%B3%A8%E5%85%A5"><span class="toc-number">1.4.8.</span> <span class="toc-text">4.8)集合类型数据注入</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-9-%E4%BD%BF%E7%94%A8p%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4%E7%AE%80%E5%8C%96%E9%85%8D%E7%BD%AE%EF%BC%88%E4%BA%86%E8%A7%A3%EF%BC%89"><span class="toc-number">1.4.9.</span> <span class="toc-text">4.9)使用p命名空间简化配置（了解）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-10-SpEL-%EF%BC%88%E4%BA%86%E8%A7%A3%EF%BC%89"><span class="toc-number">1.4.10.</span> <span class="toc-text">4.10)SpEL （了解）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-11-properties%E6%96%87%E4%BB%B6"><span class="toc-number">1.4.11.</span> <span class="toc-text">4.11)properties文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-12-%E5%9B%A2%E9%98%9F%E5%BC%80%E5%8F%91"><span class="toc-number">1.4.12.</span> <span class="toc-text">4.12)团队开发</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-13-ApplicationContext"><span class="toc-number">1.4.13.</span> <span class="toc-text">4.13)ApplicationContext</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-14-%E7%AC%AC%E4%B8%89%E6%96%B9%E8%B5%84%E6%BA%90%E9%85%8D%E7%BD%AE"><span class="toc-number">1.4.14.</span> <span class="toc-text">4.14)第三方资源配置</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E7%BB%BC%E5%90%88%E6%A1%88%E4%BE%8B"><span class="toc-number">1.5.</span> <span class="toc-text">5)综合案例</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#5-1-%E6%A1%88%E4%BE%8B%E4%BB%8B%E7%BB%8D"><span class="toc-number">1.5.1.</span> <span class="toc-text">5.1)案例介绍</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-2-%E6%A1%88%E4%BE%8B%E5%88%86%E6%9E%90"><span class="toc-number">1.5.2.</span> <span class="toc-text">5.2)案例分析</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-3-%E6%A1%88%E4%BE%8B%E5%88%B6%E4%BD%9C%E6%AD%A5%E9%AA%A4%E2%80%94%E2%80%94%E5%9F%BA%E7%A1%80%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C"><span class="toc-number">1.5.3.</span> <span class="toc-text">5.3)案例制作步骤——基础准备工作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-4-%E6%A1%88%E4%BE%8B%E5%88%B6%E4%BD%9C%E6%AD%A5%E9%AA%A4%E2%80%94%E2%80%94%E6%95%B4%E5%90%88%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C"><span class="toc-number">1.5.4.</span> <span class="toc-text">5.4)案例制作步骤——整合准备工作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-5-%E6%A1%88%E4%BE%8B%E5%88%B6%E4%BD%9C%E6%AD%A5%E9%AA%A4%E2%80%94%E2%80%94%E6%95%B4%E5%90%88%E5%B7%A5%E4%BD%9C"><span class="toc-number">1.5.5.</span> <span class="toc-text">5.5)案例制作步骤——整合工作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E8%8A%82"><span class="toc-number">1.5.6.</span> <span class="toc-text">小节</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/RabbitMQ%20Windows%20%E5%AE%89%E8%A3%85/" title="RabbitMQ Windows 安装"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="RabbitMQ Windows 安装"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/RabbitMQ%20Windows%20%E5%AE%89%E8%A3%85/" title="RabbitMQ Windows 安装">RabbitMQ Windows 安装</a><time datetime="2022-05-09T09:04:30.600Z" title="发表于 2022-05-09 17:04:30">2022-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/gateway%E5%86%85%E7%BD%AE%E8%BF%87%E6%BB%A4%E5%99%A8%E5%B7%A5%E5%8E%82/" title="Spring Cloud Gateway 内置的过滤器工厂"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="Spring Cloud Gateway 内置的过滤器工厂"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/gateway%E5%86%85%E7%BD%AE%E8%BF%87%E6%BB%A4%E5%99%A8%E5%B7%A5%E5%8E%82/" title="Spring Cloud Gateway 内置的过滤器工厂">Spring Cloud Gateway 内置的过滤器工厂</a><time datetime="2022-05-09T09:04:19.065Z" title="发表于 2022-05-09 17:04:19">2022-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/Turbine%E6%90%AD%E5%BB%BA%E6%AD%A5%E9%AA%A4/" title="Turbine"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="Turbine"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/Turbine%E6%90%AD%E5%BB%BA%E6%AD%A5%E9%AA%A4/" title="Turbine">Turbine</a><time datetime="2022-05-09T09:04:13.000Z" title="发表于 2022-05-09 17:04:13">2022-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/Eureka%20%E5%85%A8%E9%83%A8%E9%85%8D%E7%BD%AE%20/" title="Euraka配置详解"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="Euraka配置详解"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/Eureka%20%E5%85%A8%E9%83%A8%E9%85%8D%E7%BD%AE%20/" title="Euraka配置详解">Euraka配置详解</a><time datetime="2022-05-09T09:03:49.699Z" title="发表于 2022-05-09 17:03:49">2022-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/myl-mm/2022/05/09/01-Springboot-day01/" title="springBootday01"><img src="https://itcast-haoke-myl.oss-cn-beijing.aliyuncs.com/images/2022/04/13/cat1.jpg" onerror="this.onerror=null;this.src='/myl-mm/img/404.jpg'" alt="springBootday01"/></a><div class="content"><a class="title" href="/myl-mm/2022/05/09/01-Springboot-day01/" title="springBootday01">springBootday01</a><time datetime="2022-05-09T09:03:15.476Z" title="发表于 2022-05-09 17:03:15">2022-05-09</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By myl</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/myl-mm/js/utils.js"></script><script src="/myl-mm/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>